//
//  DBCommonFunctions.h
//
//  Created by Christine on 3/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "DBManager.h"

@interface DBManager (FileManage)

//Local file list: not stored in DB. When populate local file list, search in local Documents library and get the file list on real time.
//Recent file list: when opening a file, this file is stored into FileRecent table with the LastViewDate.
//Favorite file list: when set a file to be Favorite or not, this file is added/deleted from FileFavorite table.
//File tables has common properties: Path, ModifiedDate. A folder system file is exactly matching one in file table must be Path and ModifiedDate is the same.
//Recent file list and Favorite file list cannot only depends on DB table. It must also compare with the local file system and make sure the same file exist. Otherwise need to clear the deprecated one in DB table.

- (NSArray *)getRecentFileList;

//recordRecentFile also update VisitCount+1 and Valid=1
- (void)recordRecentFile:(NSString *)path modifiedDate:(NSDate *)modifiedDate lastViewDate:(NSDate *)viewedDate;
- (void)removeRecentFile:(NSString *)path;

- (void)clearRecentFile:(NSString *)path;

- (void)clearRecentTable;

- (void)replaceRecentFileFrom:(NSString *)fromPath fromModifiedDate:(NSDate *)fromModifiedDate to:(NSString *)toPath toModifiedDate:(NSDate *)toModifiedDate;

- (void)updateRecentModifiedDate:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

- (int)getVisitCount:(NSString *)path;

- (int)getLastPage:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

- (void)recordLastPage:(NSString *)path modifiedDate:(NSDate *)modifiedDate pageNum:(int)pageNum needSync:(BOOL)needSync;

- (void)resetLastPageForAllFile;

- (NSArray*)getRecentFileSyncStatus:(NSString *)path;

- (void)updateNeedSync:(NSString *)path needSync:(BOOL)needSync;

- (void)recordLastCropMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate cropMode:(int)cropMode cropInsets:(NSString *)cropInsets;
- (NSArray *)getLastCropMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

//File Favorite

- (NSArray *)getFavoriteFileList;

- (void)recordFavoriteFile:(NSString *)path fileName:(NSString *)fileName modifiedDate:(NSDate *)modifiedDate isFavorite:(BOOL)isFavorite;

- (void)removeFavoriteFile:(NSString *)path;

- (BOOL)isFavoriteFile:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

- (void)updateFavoriteModifiedDate:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

//File Cache: DB has a index for it to record modified date and cache folder path.

- (NSString *)getCachePath:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

- (NSString *)getCachePathWithoutModifiedDate:(NSString *)path;

- (void)recordCachePath:(NSString *)path modifiedDate:(NSDate *)modifiedDate cachePath:(NSString *)cachePath;

- (void)removeCachePath:(NSString *)path;

- (void)updateCachePathModifiedDate:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

- (void)replaceCacheFileFrom:(NSString *)fromPath fromModifiedDate:(NSDate *)fromModifiedDate to:(NSString *)toPath toModifiedDate:(NSDate *)toModifiedDate;

- (void)removeAllCache;

//get the open cache folder order by viewed date asc
- (NSArray *)getOpenedRemovableCacheFolderPriority;
//get the not opened cache folder
- (NSArray *)getNotopenedRemovableCacheFolderPriority;


// 文件夹同步到云端的时候存一下id
- (void)recordCloudFile:(NSString *)path userId:(NSString *) userId fileCloudId:(NSString *) fileCloudId;
// 根据文件夹路径获取文件夹id
- (NSString *)getCloudFileIdByPath:(NSString *)path userId:(NSString *) userId;
// 删除本地同步的文件夹路径
- (void)removeCloudFileIdRecord:(NSString *)fileCloudId userId:(NSString *)userId;

@end

@interface DBManager (Cloud)

//cloud account

- (NSArray *)getCloudAccountListWith:(int)cloudType;
//- (NSArray *)getCloudAccountList;
- (NSArray *)getCloudAccountList:(int)cloudType;

- (int)insertCloudAccountForType:(int)cloudType userName:(NSString *)userName;

- (BOOL)deleteCloudAccount:(int)accountId;

- (BOOL)deleteAllCloudAccount;

- (BOOL)updateCloudAccountLogTime:(double)lastLogTime withToken:(NSString *)token withUserId:(NSString *)userId forAccount:(int)accountId;

- (NSArray *)getCloudAccountByUserId:(NSString *)userId;
- (NSArray *)getCloudAccountByUserId:(NSString *)userId andCloudType:(int)cloudType;

- (BOOL)updateCloudAccountToken:(NSString *)newToken oldToken:(NSString *)oldToken;

- (BOOL)updateCloudAccount:(NSString*)userName withToken:(NSString *)token forAccount:(int)accountId;

- (BOOL)updateCloudSyncAccountId:(int)accountId;

//cloud sync folder

- (NSArray *)getCloudSyncFolder;

- (NSArray *)getCloudSyncFolderForAccount:(int)accountId;

- (int)insertCloudSyncFolderForAccount:(int)accountId serverPath:(NSString *)serverPath localPath:(NSString *)localPath displayName:(NSString *)displayName;

- (BOOL)deleteCloudSyncFolder:(int)syncId;

- (BOOL)updateCloudSyncEnabled:(BOOL)isEnabled forSync:(int)syncId;

//cloud data

- (NSArray *)getCloudDataForSyncFolder:(int)syncId;

- (NSArray *)getCloudNeedSyncDataForSyncFolder:(int)syncId;

- (NSArray *)getCloudDataForServerFolder:(NSString *)serverFolder inSync:(int)syncId;

- (NSArray *)getCloudDataForLocalFolder:(NSString *)localFolder inSync:(int)syncId;

- (NSArray *)getCloudDataForLocalPath:(NSString *)path;

- (int)insertCloudDataForSync:(int)syncId serverPath:(NSString *)serverPath localPath:(NSString *)localPath serverHash:(NSString *)serverHash serverSyncStatus:(int)serverStatus clientSyncStatus:(int)clientStatus displayName:(NSString *)displayName isDirectory:(BOOL)isDirectory rev:(NSString *)rev fileType:(NSString *)fileType fileSize:(unsigned long long)fileSize lastModifiedDate:(double)lastModifiedDate;

- (BOOL)updateCloudDataServerPath:(NSString *)serverPath hash:(NSString *)hash rev:(NSString *)rev serverSyncStatus:(int)status forData:(int)dataId;

- (BOOL)updateCloudDataClientPath:(NSString *)localPath clientSyncStatus:(int)status forData:(int)dataId;

- (BOOL)updateCloudDataFileSize:(unsigned long long)fileSize forData:(int)dataId;

- (BOOL)updateCloudDataLastModifiedDate:(double)lastModifiedDate forData:(int)dataId;

- (BOOL)updateDisplayName:(NSString *)displayName forData:(int)dataId;

- (BOOL)updateIsDirectory:(BOOL)isDirectory forData:(int)dataId;

- (BOOL)deleteCloudData:(int)dataId;

- (NSArray *)getLastClientStatusForData:(int)dataID;

- (NSArray *)getLastServerStatusForData:(int)dataID;

@end

@interface DBManager (Review)

- (BOOL)deleteReviewData:(NSString*)reviewID;

- (int)insertReviewersForReviewID:(int)dataID
                         reviewID:(NSString*)reviewID
                            email:(NSString*)email
                             name:(NSString*)name
                            title:(NSString*)title
                             type:(NSString*)type
                       annotCount:(NSString*)annotCount;

- (BOOL)updateReviewersForReviewID:(NSString*)reviewID
                             email:(NSString*)email
                              name:(NSString*)name
                             title:(NSString*)title
                              type:(NSString*)type
                        annotCount:(NSString*)annotCount;

- (NSArray *)getReviewersForReivewID:(NSString*)reviewID;



- (BOOL)deleteDocInfoData:(NSString*)reviewID;

- (int)insertDocInfoForReviewID:(int)dataID
                       reviewID:(NSString*)reviewID
                    fileType:(NSString*)fileType
                    fileName:(NSString*)fileName
                    filePath:(NSString*)filePath
                    sendDate:(NSString*)sendDate
                    deadDate:(NSString*)deadDate
                   fromEmail:(NSString*)fromEmail
                     toEmail:(NSString*)toEmail
                      statue:(NSString*)statue;

- (BOOL)updateDocInfoForReviewID:(NSString*)reviewID
                        fileType:(NSString*)fileType
                        fileName:(NSString*)fileName
                        filePath:(NSString*)filePath
                        sendDate:(NSString*)sendDate
                        deadDate:(NSString*)deadDate
                       fromEmail:(NSString*)fromEmail
                         toEmail:(NSString*)toEmail
                          statue:(NSString*)statue;

- (BOOL)updateDocInfoStatusForReviewID:(NSString*)reviewID status:(NSString*)status;

- (NSArray *)getDocInfoForReviewID:(NSString*)reviewID;

- (BOOL)updateDocInfoPathForReviewID:(NSString*)reviewID path:(NSString*)path;


//ThumbnialImage




@end
